/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
 */

package com.huawei.exam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author z00611952
 * @since 2021/9/17
 */
public class Main3 {
    /**
     * main入口由OJ平台调用
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
        String[] marblesStr = br.readLine().split(" ");
        br.close();
        int[] marbles = Arrays.stream(marblesStr).mapToInt(Integer::parseInt).toArray();
        Solution3 solution = new Solution3();
        List<Integer> result = solution.getRemainingMarbles(marbles);
        if (result == null) {
            System.out.print("[]");
        } else {
            System.out.print("[" + result.stream().map(String::valueOf).collect(Collectors.joining(" ")) + "]");
        }
    }
}

class Solution3 {
    // 待实现函数，在此函数中填入答题代码
    List<Integer> getRemainingMarbles(int[] marbles) {
        boolean[] vis = new boolean[marbles.length];
        int count = marbles.length;
        for (int i = 1; i < marbles.length - 1; i++) {
            // left 是左边第一个为false的
            int left = getLeft(marbles, vis, i);
            int self = marbles[i];
            if (isOpsite(left, self) && !isSame(left, self)) {
                // 如果是反向
                if (Math.abs(left) > Math.abs(self)) {
                    // 移除self
                    vis[i] = true;
                    count--;
                } else if (Math.abs(left) < Math.abs(self)) {
                    vis[i - 1] = true;
                    count--;
                } else {
                    vis[i] = true;
                    vis[i - 1] = true;
                    count -= 2;
                }
            }
        }
        List<Integer> result = new ArrayList<>();
        if (count == 0) {
            return result;
        }
        for (int i = 0; i < marbles.length; i++) {
            if (!vis[i]) {
                result.add(marbles[i]);
            }
        }
        return result;
    }

    // 3 -5 6 -7 4 -4 3 -5 6 -7 4 -4 3 -5 6 -7 4 -4 3 -5 6 -7 4 -4 3 -5 6 -7 4 -4 3 -5 6 -7 4 -4 3 -5 6 -7 4 -4 3 -5 6
    // -7 4 -4
    private int getLeft(int[] marbles, boolean[] vis, int pos) {
        int left = marbles[pos - 1];
        int find = pos - 1;
        while (find >= 0) {
            if (!vis[find]) {
                left = marbles[find];
                break;
            }
            find--;
        }
        return left;
    }

    private boolean isNegative(int number) {
        return number < 0;
    }

    private boolean isOpsite(int num1, int num2) {
        return (isNegative(num1) && !isNegative(num2)) || (!isNegative(num1) && isNegative(num2));
    }

    private boolean isSame(int left, int right) {
        return left < 0 && right > 0;
    }
}
